package com.gjy.disruptor.bv1qu411d7oh.t1;

import com.lmax.disruptor.EventHandler;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @author gjy
 * @version 1.0
 * @since 2025-04-04 13:07:45
 */
public class DataConsumer implements EventHandler<Data> {

    private final long start;
    private int i;
    private final List<Integer> list = new CopyOnWriteArrayList<>();
    private static final Integer MAX_SIZE = 5000;

    public DataConsumer() {
        start = System.currentTimeMillis();
    }

    @Override
    public void onEvent(Data data, long l, boolean b) throws Exception {
        list.add(i);
        i++;
        if (b || list.size() >= MAX_SIZE || i == Constants.EVENT_NUM_OM) {
            System.out.println(Thread.currentThread().getName() + "Disruptor: " + (System.currentTimeMillis() - start) + ": " + list.size());
            list.clear();
        }
    }
}
